package com.kedi.journalismcenter.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kedi.journalismcenter.read.dao.mapper.ReadHeadlineMapper;
import com.kedi.journalismcenter.service.HeadlineService;
import com.kedi.journalismcenter.write.dao.mapper.PcHeadlineMapper;

/**
 * 
 *
 * @ClassName AgeNewsService
 * @author: 陈辽逊
 * @date: 2019/7/13 11:21
 */

@Service
public class HeadlineServiceImpl implements HeadlineService {

	@Autowired
	public ReadHeadlineMapper rmapper;
	@Autowired
	public PcHeadlineMapper wmapper;

	final static Logger logger = LoggerFactory.getLogger(HeadlineServiceImpl.class);

	/**
	 * @return 返回一个国内新闻数据对象
	 */
	@Override
	public List<Map<String, Object>> homenews(int page,int limit) {
		try {
			List<Map<String, Object>>  a = rmapper.homenews(page,limit);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个国际新闻数据对象
	 */
	@Override
	public List<Map<String, Object>> internationalnews(int page,int limit) {
		try {
			List<Map<String, Object>>  a = rmapper.internationalnews(page,limit);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个省内新闻数据对象
	 */
	@Override
	public List<Map<String, Object>> provincialnews(int page,int limit) {
		try {
			List<Map<String, Object>>  a = rmapper.provincialnews(page,limit);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个老人新闻数据对象
	 */
	@Override
	public List<Map<String, Object>> agenews(int page,int limit) {
		try {
			List<Map<String, Object>>  a = rmapper.agenews(page,limit);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个国内新闻数据对象根据id
	 */
	@Override
	public Map<String, Object> homenewsDetailByid(int id) {
		try {
			Map<String, Object>  a = rmapper.homenewsDetailByid(id);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个国际新闻数据对象根据id
	 */
	@Override
	public Map<String, Object> internationalnewsDetailByid(int id) {
		try {
			Map<String, Object>  a = internationalnewsDetailByid(id);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个省内新闻数据对象根据id
	 */
	@Override
	public Map<String, Object> provincialnewsDetailByid(int id) {
		try {
			Map<String, Object>  a = rmapper.provincialnewsDetailByid(id);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 返回一个老人新闻数据对象根据id
	 */
	@Override
	public Map<String, Object> agenewsDetailByid(int id) {
		try {
			Map<String, Object>  a = rmapper.agenewsDetailByid(id);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询失败");
			return null;
		}
	}

	/**
	 * @return 创建国内新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean ihomenewsPhotos(Map map) {
		int a = wmapper.ihomenews(map);
		int b = wmapper.ihomesource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 修改国内新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean homenewsPhotos(Map map) {
		int a = wmapper.homenews(map);
		int b = wmapper.homesource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 创建国际新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean iinternationalnewsPhotos(Map map) {
		int a = wmapper.iinternationalnews(map);
		int b = wmapper.iintersource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 修改国际新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean internationalnewsPhotos(Map map) {
		int a = wmapper.internationalnews(map);
		int b = wmapper.intersource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 创建省内内新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public int iprovincialnewsPhotos(Map map) {
		int a = wmapper.iprovincialnews(map);
		int b = wmapper.iprovsource(map);
		if (a == 1 && b == 1) {
			return 1;
		} else {
			return 0;
		}
	}

	/**
	 * @return 修改省内新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean provincialnewsPhotos(Map map) {
		int a = wmapper.provincialnews(map);
		int b = wmapper.provsource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 创建老人新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean iagenewsPhotos(Map map) {
		int a = wmapper.iagenews(map);
		int b = wmapper.iagenewssource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 修改老人新闻和图片资源信息
	 */
	@Override
	@Transactional(rollbackFor = Exception.class, transactionManager = "secondaryTransactionManager")
	public boolean agenewsPhotos(Map map) {
		int a = wmapper.agenews(map);
		int b = wmapper.agenewssource(map);
		if (a == 1 && b == 1) {
			return true;
		} else {
			return false;
		}
	}

}
